<template>
    <div class="poa">
        <top @leftfn="back" :left="'el-icon-arrow-left'" :title="'修改密码'" />
        <div class="gun">
            <form_input :value.sync="oldpassword" :text="'输入旧密码'" />
            <form_input :value.sync="form.newpassword" :text="'输入新密码'" />
            <form_input :value.sync="form.renewpassword" :text="'输入确认密码'" />
            <submit @yes="submit_login" :form="form" :text="'设置'" />
            <div class="bt"></div>
        </div>
    </div>
</template> 
<script>
import form_input from './common/form_input.vue';
import submit from './common/submit.vue';
import top from './common/top.vue'
export default ({
    components: {
        top,
        submit,
        form_input,
    },
    data() {
        return {
            oldpassword: '',
            form: {
                newpassword: '',
                renewpassword: '',
            },
        }
    },
    methods: {
        submit_login() {
            if (JSON.parse(localStorage.getItem('token')).password) {
                if (JSON.parse(localStorage.getItem('token')).password !== this.oldpassword) {
                    return this.$TiShi({ text: '旧密码不对' })
                }
            }
            if (this.form.newpassword !== this.form.renewpassword) {
                return this.$TiShi({ text: '两次输入密码不一致' })
            }
            this.$http({
                url: 'http://43.138.15.137:8085/api/repassword',
                method: 'post',
                data: {
                    oldpassword: this.oldpassword,
                    newpassword: this.form.newpassword,
                    renewpassword: this.form.renewpassword,
                },
            }).then(res => {
                this.$TiShi({ text: res.data.msg })
                this.$router.go(-1)
            }, (res => {
                this.$TiShi({ text: res.data.msg })
                this.$router.go(-1)
            }))
        },
        back() {
            this.$router.go(-1)
        },
    },
})
</script>
<style scoped lang="scss">
@function r($v) {
    @return $v / (390 /10rem)
}
</style>